{include file="public/header" /}

<div class="page" style="min-height: 300px;">

    <form id="goods_class_form" method="post" action=''>
        <table class="ds-default-table">
            <tbody>

            <tr class="noborder" style="background: rgb(255, 255, 255);">
                <td class="required w120"><label class="validation">店铺类型:</label></td>
                <td class="vatop rowform">
                    <select name="inquiry_id" id="inquiry_id" title="">
                        <option value="0">请选择店铺类型</option>
                        {notempty name="inquiry_list"}
                        {foreach name="inquiry_list" item="val"}
                        <option value="{$val.id}">{$val.inquiry_name}</option>
                        {/foreach}
                        {/notempty}
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>

            <tr class="noborder" style="background: rgb(255, 255, 255);">
                <td class="required w120"><label class="validation">工位选择:</label></td>
                <td class="vatop rowform">
                    <select name="station_id" title="" id="station_ids">
                        <option value="0">请选择工位</option>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>

            <tr class="noborder" style="background: rgb(255, 255, 255);">
                <td class="required w120"><label class="validation">配置信息:</label></td>
                <td class="vatop rowform">
                    {foreach name="config_list" key="key" item="va"}
                    <label class="checkbox-label"  for="{$va.'-'.$key}">
                        <i class="checkbox-common">
                            <input type="checkbox" name="good_config" value="{$key}" id="{$va.'-'.$key}" >
                        </i>
                        <span>{$va}</span>
                    </label>
                    {/foreach}
                </td>
                <td class="vatop tips"></td>
            </tr>


            <tr class="noborder" style="background: rgb(255, 255, 255);">
                <td class="required w120"><label class="validation">数量:</label></td>
                <td class="vatop rowform">
                     <input type="text"  name="num" id="num" class="txt" oninput="value=value.replace(/[^\d]/g,'')">
                </td>
                <td class="vatop tips"></td>
            </tr>

            </tbody>
            <tfoot>
                <tr>
                    <td colspan="2">
                        <input class="btn" type="button" onclick="import_inquiry('{$goods_id}')" value="{$Think.lang.ds_submit}" />
                    </td>
                </tr>
            </tfoot>
        </table>
    </form>
</div>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js" charset="utf-8"></script>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/jquery.mousewheel.js"></script>
<script>
    //按钮先执行验证再提交表单
    $(function() {
        $('.btn').click(function(){
            var title = $("input[name='inquiry_name']").val();
            if ( title.length ==0) {
                alert('店铺分类不能为空');
                return;
            }
            $('#goods_class_form').submit();
        });
    });
</script>

<script>
    $(function (){
        // 动态获取工位
        $('#inquiry_id').change(function(){
            var inquiry_id = $(this).val();
            $.ajax({
                type: 'post',
                url: ADMINSITEURL + '/Goodinquiry/get_station',
                data: {'inquiry_id' : inquiry_id},
                dataType: 'json',
                success: function(res) {
                    if(res.code > 0) {
                        var options = '';
                        $.each(res.data, function(idx, obj) {
                            options += "<option value='"+ obj.station_id +"'>" + obj.station_name +"</option>"
                        });
                        $('#station_ids').append(options);
                    } else {
                        $('#station_ids').empty().append('<option value="0">请选择工位</option>');
                    }
                },
                error: function () {
                    layer.msg('系统繁忙，请稍后再试！');
                }
            })
        })
    });

    function import_inquiry ($goods_id)
    {
        var inquiry_id = $('#inquiry_id').val();
        var station_id = $('#station_ids').val();
        var num = $('#num').val();
        var good_configs = [];
        $("input[type=checkbox][name=good_config]").each(function(){
            if($(this).prop('checked')){
                good_configs.push($(this).val());
            }
        });

        $.ajax({
            type: 'post',
            url: ADMINSITEURL + '/Goodinquiry/import_inquiry',
            data: {'inquiry_id' : inquiry_id, 'goods_id' : $goods_id, 'station_id': station_id, 'good_config': good_configs.join(','),'num': num, },
            dataType: 'json',
            success: function(res) {
                console.log(res);
                if(res.code > 0) {
                    layer.msg(res.msg);
                     parent.location.reload()
                            } else {
                    layer.msg(res.msg);
                }
            },
            error: function () {
                layer.msg('系统繁忙，请稍后再试！');
            }
        })
    }
</script>


